"""
五子棋WebSocket路由配置

配置五子棋模块的WebSocket路由，包括实时游戏连接等端点。
"""

from fastapi import APIRouter, WebSocket, WebSocketDisconnect, Depends, Query
from sqlalchemy.ext.asyncio import AsyncSession

from app.db.session import get_db
from app.modules.gomoku.config import settings
from app.modules.gomoku.websockets.game import handle_game_connection

# 创建WebSocket路由器
router = APIRouter()


@router.websocket(f"{settings.WS_URL_PREFIX}/game/{{game_id}}")
async def game_websocket(
    websocket: WebSocket,
    game_id: int,
    token: str = Query(...),
    is_spectator: bool = Query(False),
    db: AsyncSession = Depends(get_db)
):
    """
    五子棋游戏WebSocket连接
    
    处理实时游戏通信，包括落子、聊天等。
    
    参数:
    - game_id: 游戏ID
    - token: 认证令牌
    - is_spectator: 是否是观战者
    """
    await handle_game_connection(
        websocket=websocket,
        game_id=game_id,
        token=token,
        is_spectator=is_spectator,
        db=db
    ) 